// $Id: Game.h 127 2007-11-17 15:07:25Z bram $


/**
 * Game class header file.
 *
 * @file Game.h
 * @author Bram Bonn&eacute;
 * @author Wim Leers
 */


#ifndef GAME_H
#define GAME_H

#include <string>
#include <stack>
using namespace std;
#include "Board.h"
#include "Player.h"
#include "PlayerDB.h"
#include "InternalException.h"
#include "FileIO.h"

enum Directions { LEFT, LEFTUP, UP, RIGHTUP, RIGHT, RIGHTDOWN, DOWN, LEFTDOWN };

class Game {
	public:
		Game(string p1Name, string p2Name);
		virtual ~Game(void);
		int CountPieces(Piece piece) const;
		Board GetBoard(void) const { return * m_board; }
		Piece GetActive(void) const { return m_active; }
		bool ValidMovePossible(Piece piece) const;
		bool TryPieceMove(Piece piece, int x, int y);
		bool BothMovePossible();
		bool Load(void);
		void Save(void);
	private:
		Piece m_active;
		int m_moveNumber;
		stack<Board> m_history;
		Board * m_board;
		Player * m_player1, * m_player2;
		static const int SIZE;
		static const string FILENAME;
		PlayerDB m_db;
		FILEIO_TABLE m_table;
		FileIO m_fileIO;

		Player * GetOrCreatePlayer(string playerName);
		void SetStartPosition(void);
		void FlipPieces (int x1, int y1, int x2, int y2, Directions direction) const;
		bool IsValidMove(Piece piece, int x, int y) const;
		bool CheckAllDirections(Piece piece, int x, int y, bool performMove) const;

		// Helpfuncties voor CheckAllDirections().
		bool CheckRight(Piece piece, int x, int y, bool performMove) const;
		bool CheckLeft(Piece piece, int x, int y, bool performMove) const;
		bool CheckRightUp(Piece piece, int x, int y, bool performMove) const;
		bool CheckRightDown(Piece piece, int x, int y, bool performMove) const;
		bool CheckLeftUp(Piece piece, int x, int y, bool performMove) const;
		bool CheckLeftDown(Piece piece, int x, int y, bool performMove) const;
		bool CheckUp(Piece piece, int x, int y, bool performMove) const;
		bool CheckDown(Piece piece, int x, int y, bool performMove) const;
};

#endif
